import { _decorator, Component, Node, Sprite, Vec3 } from 'cc';
import { ResMgr } from '../Managers/ResMgr';
import { SpriteUtil } from '../Utils/SpriteUtil';
import { ChessCommon } from './ChessCommon';
const { ccclass, property } = _decorator;

/**
 * 显示移动的棋子外框
 */
@ccclass('ChessPane')
export class ChessPane extends Component {
    /**
     * 
     */
    private _sprite:Sprite;
    private get sprite():Sprite{
        if(!this._sprite){
            this._sprite = this.node.getComponent(Sprite);
        }
        return this._sprite;
    }
    /**
     * 
     */
    private _my:number = 0;
    
    start() {

    }
    /**
     * 坐标
     * @param x 
     * @param y 
     * @returns 
     */
    public SetPos(x:number, y:number):ChessPane{
        this.node.setPosition(ChessCommon.convertRowColToChessPos(x, y));
        return this;
    }
    /**
     * 1:红方，-1:黑方
     * @param value 
     * @returns 
     */
    public SetMy(value:number):ChessPane{
        this._my = value;
        SpriteUtil.Instance.setChessAtlasSpriteFrame(this.sprite, this._my == 1 ? "r_box" : "b_box");
        return this;
    }

    public SetActive(value:boolean):ChessPane{
        this.node.active = value;
        return this;
    }
}

